package org.example.lottery_system.controller;

import jakarta.validation.Valid;
import org.example.lottery_system.common.pojo.CommonResult;
import org.example.lottery_system.common.utils.JacksonUtil;
import org.example.lottery_system.controller.param.CreatePrizeParam;
import org.example.lottery_system.service.PictureService;
import org.example.lottery_system.service.PrizeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class PrizeController {
    private static Logger logger = LoggerFactory.getLogger(PrizeController.class);

@Autowired
    private PictureService pictureService;

@Autowired
private PrizeService prizeService;

@RequestMapping("/pic/upload")
    public String uploadPic(MultipartFile file){
    return pictureService.savePicture(file);
}

@RequestMapping("/prize/create")
    public CommonResult<Long> createPrize(
            @Valid @RequestPart("Param") CreatePrizeParam param,@RequestPart("prizePic") MultipartFile picFile){
logger.info("createPrize CreatePrizeParam:{}", JacksonUtil.writeValueAsString(param));
return CommonResult.success(prizeService.createPrize(param,picFile));
}

}
